package com.freesun.shop.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.freesun.shop.entity.Transport;
import com.freesun.shop.service.TransportService;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shop/transport")
public class TransportFeeController {

    @Reference(check = false)
    private TransportService transportService;

    @ApiOperation("分页条件查询运费模板")
    @GetMapping("/page")
    public ResponseEntity<IPage<Transport>> findByPage(Transport transport, Page<Transport> page) {
        IPage<Transport> iPage = transportService.findByPage(transport, page);
        return ResponseEntity.ok(iPage);
    }

    @ApiOperation("新增一个运费模板")
    @PostMapping
    public ResponseEntity<Void> saveTransport(@RequestBody Transport transport) {
        transportService.save(transport);
        return ResponseEntity.ok().build();
    }

    @ApiOperation("查询一个运费模板")
    @GetMapping("/info/{id}")
    public ResponseEntity<Transport> findById(@PathVariable Long id) {
        Transport transport = transportService.getById(id);
        return ResponseEntity.ok(transport);
    }

    @ApiOperation("批量删除模板")
    @DeleteMapping
    public ResponseEntity<Void> batchDelete(@RequestBody List<Long> ids) {
        transportService.removeByIds(ids);
        return ResponseEntity.ok().build();
    }

    @ApiOperation("修改运费模板")
    @PutMapping
    public ResponseEntity<Void> update(@RequestBody Transport transport) {
       transportService.updateById(transport);
        return ResponseEntity.ok().build();
    }

    @ApiOperation("查询物流模板")
    @GetMapping("/list")
    public ResponseEntity<List<Transport>> list() {
        List<Transport> transportList = transportService.list();
        return ResponseEntity.ok(transportList);
    }
}
